/* ----------------------------------------------------------------------------
 * ssjs
 * ----------------------------------------------------------------------------
 * File Name    : debug.js
 * Module       : debug
 * Dependicies  : system, http
 * Description  : Implemets methods for logging
 * ----------------------------------------------------------------------------
 * $LastChangedBy$
 * $LastChangedDate$
 * $LastChangedRevision$
 * $HeadURL$
 * -------------------------------------------------------------------------- */

var debug = function() {
    var module = this.prototype;

    module.dump = function(obj) {
        if(obj === null) { return "null"; }
        if(obj === undefined) { return "undefined"; }

        switch (obj.constructor) {
            case Array:
                var arr = ['(array)', "<ul>"];

                for (var ndx = 0; ndx < obj.length; ++ndx) {
                    arr.push("<li>" + ndx + ": " + module.dump(obj[ndx]) + "</li>");
                }

                arr.push("</ul>");

                return arr.join('');

            case Boolean:
                return "<span style='color: blue;'>" + obj +"</span>";

            case Function:
                 var prototypeFunctions = [];

                 for(var fct in obj.prototype) {
                    prototypeFunctions.push(fct);
                 }

                 return "( " + prototypeFunctions.join(',') +" )";

            case Number:
                return "<span style='color: blue;'>" + obj +"</span>";

            case Object:
                var obs = ["<ul>"];

                for (var key in obj) {
                    if (obj.hasOwnProperty(key) && key != 'global') {
                        obs.push("<li>" + key + ": "+ module.dump(obj[key]) + "</li>");
                    }
                }

                 obs.push("</ul>");

                return obs.join('');

            case RegExp:
                return "<span style='color: blue;'>\"" + obj +"\"</span>";

            case String:
                return "<span style='color: green;'>\"" + obj +"\"</span>";
        }

        var result = ["<ul>"];

        for(var key in obj) {
            if(obj.hasOwnProperty(key) && key != "global") {
                result.push("<li>" + key + ": " + module.dump(obj[key]) + "</li>");
            }
        }

        result.push("</ul>");

        return result.join('');
    };

};

exports.debug = debug;

